{include file="public/header"}
<body>
<div id="app" v-cloak>
    <div class="ht-main">
        <div class="ht-search">
            <el-form :inline="true" size="small">
                <el-form-item label="订单号">
                    <el-input type="text" placeholder="订单号" v-model="searchKey.rand_no"></el-input>
                </el-form-item>
                <el-form-item label="厂区">
                    <el-select v-model="searchKey.factory_id" placeholder="请选择">
                        <el-option label="全部" value=""></el-option>
                        <el-option :label="item.title" :value="item.id" v-for="item in factory_list" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="创建时间">
                    <el-date-picker
                            v-model="searchKey.create_time"
                            type="daterange" format="yyyy-MM-dd"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            value-format="yyyy-MM-dd">
                    </el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" icon="el-icon-search" @click="search">搜索</el-button>
                    <el-button type="" icon="el-icon-refresh" @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="ht-tool">
            <div class="ht-tool-left">
                <el-button type="success" size="mini" icon="el-icon-plus" @click="doAdd">添加</el-button>
                <el-button type="primary" :disabled="tableSelect.length !== 1" size="mini" icon="el-icon-edit"
                           @click="edit(tableSelect[0])">编辑
                </el-button>
                <el-button type="danger" :disabled="!tableSelect.length" size="mini" icon="el-icon-delete"
                           @click="batchDel('/admin/ai.vip_order/del')">删除
                </el-button>
            </div>
            <div class="ht-tool-right">
            </div>
        </div>
        <div class="ht-main-body">
            <el-table :data="tableData" border header-row-class-name="ht-table-header"
                      ref="dataTable" @selection-change="handleSelectChange">
                <el-table-column align="center" type="selection" width="39"></el-table-column>
                <el-table-column align="center" prop="user" width="100px" label="头像">
                    <template slot-scope="scope">
                        <img :src="scope.row.user.avatar" style="max-width: 50px;border-radius: 50%" @click="showImg(scope.rowuser.avatar)">
                    </template>
                </el-table-column>
                <el-table-column prop="user.nick" label="昵称"></el-table-column>
                <el-table-column align="center" prop="xianqi" label="仙气"></el-table-column>
                <el-table-column align="center" prop="money" label="金额"></el-table-column>
                <el-table-column align="center" prop="status" label="状态">
                    <template slot-scope="scope">
                        <el-tag effect="dark" size="mini" type="success" v-if="scope.row.status === 1">已支付</el-tag>
                        <el-tag effect="dark" size="mini"  type="danger" v-else>未支付</el-tag>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="操作" width="160">
                    <template slot-scope="scope">
                        <el-link @click="del(scope.row)" type="danger" >删除</el-link>
                    </template>
                </el-table-column>
            </el-table>
            <div class="ht-main-page">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page"
                        :page-sizes="[1,10,20,50, 200, 300, 400]"
                        :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
            <el-drawer
                    :visible.sync="is_edit"
                    size="100%"
                    :with-header="false"
                    custom-class="ht-drawer-bg"
            >
                <div class="ht-drawer-main">
                    <el-page-header @back="goBack" title="Esc返回" :content="content"></el-page-header>
                    <div class="ht-form">
                        <el-form :model="editData" label-width="120px" size="small">
                            <el-form-item label="仙气">
                                <el-input placeholder="仙气"  v-model="editData.xianqi"></el-input>
                            </el-form-item>
                            <el-form-item label="价格">
                                <el-input placeholder="价格" v-model="editData.money"></el-input>
                            </el-form-item>
                            <el-form-item label="排序">
                                <el-input placeholder="排序" v-model="editData.sort"></el-input>
                            </el-form-item>
                            <el-form-item>
                                <el-button @click="goBack">取消</el-button>
                                <el-button type="primary" @click="onSubmit">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </el-drawer>
        </div>
    </div>
</div>
{include file="public/common"}
<script src="/static/elementUi/component/device.js"></script>
<script src="/static/elementUi/component/parts.js"></script>

<script>
    let vs ;
    let del_url = "{:url('ai.vip_order/del')}";
    let add_url = "{:url('ai.vip_order/add')}";
    let index_url = "{:url('ai.vip_order/index')}";
    var vm = new Vue({
        el: "#app",
        data: function () {
            return {
                inputValue: '',
                deviceShow:false,
                partsShow:false,
                showSign: false,
                showDialog: false,
                showDoSign:false,
                showLiu:false,
                activeTab: 'first',
                tableData: [],
                is_edit: false,
                editData: {
                    device_info:[],
                    parts_info:[],
                    sign_info:{}
                },
                editDataTemp: {},
                content: '编辑',
                total: 0,
                page: 1,
                limit: 10,
                deviceData:[],
                partsData:[],
                sizeList:["720*1280",'1024*1024','1280*720'],
                parts_list:[],
                device_list:[],
                factory_list:[],
                diggings_list:[],
                itemData:{}
            }
        },
        created: function () {
            vs = this;
            vs.getData()
        },
        methods: {
            doSee(row) {
                Api.request("{:url('ai.order/doSee')}",{
                    id:row.id
                }).then(res=>{
                    top.showImages(res.data.images,1,res.data.order.prompt)
                })
            },
            doCreate(row) {
                Api.request("{:url('ai.order/doCreate')}",{
                    id:row.id
                }).then(res=>{
                    vs.showSuccessMsgCall(function () {
                        vs.getData()
                    })
                })
            },
            doPull(row) {
                Api.request("{:url('ai.order/doPull')}",{
                    id:row.id
                }).then(res=>{
                    vs.showSuccessMsgCall(function () {
                        vs.getData()
                    })
                })
            },
            getIndex() {
                vs.getData()
            },
            onSubmit() {
                var that = this
                $.post(add_url, that.editData, function (res) {
                    if (res.code == 1) {
                        that.showSuccessMsgCall(function () {
                            that.is_edit = false;
                            that.showDoSign = false
                            that.showLiu = false
                            that.editData = {
                                parts_info:[],
                                device_info: [],
                                sign_info:{}
                            };
                            location.reload()
                            // that.getData()
                        })
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },

            getData: function () {
                var that = this
                that.searchType = {
                    order_no: 'like',
                    create_time:'between time'
                }
                $.post(index_url, {
                    limit: that.limit,
                    page: that.page,
                    search_key: that.searchKey,
                    search_type: that.searchType
                }, function (res) {
                    if (res.code == 1) {
                        that.tableData = res.data.data
                        that.total = res.data.total
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },
            doAdd: function () {
                this.is_edit = true
                this.content = '添加'
                this.editData = {
                    parts_info:[],
                    device_info: [],
                    sign_info:{}
                }
            },
            edit: function (data) {
                this.is_edit = true
                this.content = '编辑'
                this.editData = data
                if (!this.editData.sign_info) {
                    this.editData.sign_info = {}
                }
            },
            goBack: function () {
                this.is_edit = false
            },
            del: function (data) {
                var that = this
                that.$confirm('确定删除么?', '提示', {
                    type: 'warning',
                    lockScroll: false
                }).then(() => {
                    $.post(del_url, {id: data.id}, function (res) {
                        if (res.code == 1) {
                            that.showSuccessMsgCall(function () {
                                that.getData()
                            })
                        } else {
                            that.showErrorMsg(res.msg)
                        }
                    })
                })
            },
            handleSizeChange: function (e) {
                this.limit = e
            },
            handleCurrentChange: function (e) {
                this.page = e
            }
        },
        watch: {
            page(v) {
                this.getData()
            },
            limit() {
                this.getData()
            }
        }
    })
</script>
</body>
</html>
